WPS Office.apk(点击下载) / ixa.java


package defpackage;

import android.graphics.Bitmap;
import android.support.v4.app.NotificationCompat;
import cn.wps.moffice.OfficeApp;
import cn.wps.moffice.pdf.core.std.PDFPage;
import com.baidu.tts.loopj.AsyncHttpResponseHandler;
import com.google.firebase.perf.FirebasePerformance;
import com.google.gson.GsonBuilder;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechEvent;
import com.iflytek.cloud.SpeechUtility;
import defpackage.iwx;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.BindException;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.james.mime4j.util.CharsetUtil;
import org.json.JSONObject;

/* renamed from: ixa  reason: default package */
public final class ixa implements iwx {
    private String itd = "https://moapi.wps.cn/sign/api/file/upload";
    private String kgJ = "https://moapi.wps.cn/sign/api/user/isreg";
    private String kgK = "https://moapi.wps.cn/sign/api/file/sign";
    private String kgL = "https://moapi.wps.cn/sign/api/file/verify";

    /* access modifiers changed from: package-private */
    /* renamed from: ixa$a */
    public static class a {
        public HashMap<String, String> dyQ;
        public String isW;
        public boolean isX;
        public String url;

        private a() {
        }

        /* synthetic */ a(byte b) {
            this();
        }

        public final a DX(String str) {
            this.isX = true;
            this.isW = str;
            return this;
        }
    }

    private String a(a aVar) throws Exception {
        try {
            return aVar.isX ? lwd.c(aVar.url, aVar.isW, aVar.dyQ) : lwd.f(aVar.url, aVar.dyQ);
        } catch (Exception e) {
            if (!((e instanceof ConnectException) || (e instanceof BindException) || (e instanceof SocketException) || (e instanceof SocketTimeoutException))) {
                return null;
            }
            throw e;
        }
    }

    private String a(a aVar, File file, iwx.a aVar2) throws Exception {
        OutputStream outputStream;
        Exception e;
        BufferedInputStream bufferedInputStream;
        BufferedInputStream bufferedInputStream2 = null;
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(aVar.url).openConnection();
        httpURLConnection.setUseCaches(false);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setRequestMethod(FirebasePerformance.HttpMethod.POST);
        httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
        httpURLConnection.setRequestProperty("Cache-Control", "no-cache");
        HashMap<String, String> hashMap = aVar.dyQ;
        for (String str : hashMap.keySet()) {
            httpURLConnection.setRequestProperty(str, hashMap.get(str));
        }
        httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=e2cbeeea-d3e2-4f59-af36-438b4ffa155d");
        long ar = ar(file);
        httpURLConnection.setFixedLengthStreamingMode((int) ar);
        httpURLConnection.setRequestProperty("Content-Length", String.valueOf(ar));
        try {
            outputStream = httpURLConnection.getOutputStream();
            try {
                a(outputStream, file, aVar2);
                iww.a(outputStream);
                StringBuilder sb = new StringBuilder();
                try {
                    bufferedInputStream = new BufferedInputStream(httpURLConnection.getInputStream());
                    try {
                        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            }
                            sb.append(readLine).append("\n");
                        }
                        iww.x(bufferedInputStream);
                        try {
                            httpURLConnection.disconnect();
                        } catch (Exception e2) {
                        }
                        return sb.toString();
                    } catch (Exception e3) {
                        e = e3;
                        bufferedInputStream2 = bufferedInputStream;
                        try {
                            throw e;
                        } catch (Throwable th) {
                            th = th;
                            bufferedInputStream = bufferedInputStream2;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        iww.x(bufferedInputStream);
                        try {
                            httpURLConnection.disconnect();
                        } catch (Exception e4) {
                        }
                        throw th;
                    }
                } catch (Exception e5) {
                    e = e5;
                    throw e;
                } catch (Throwable th3) {
                    th = th3;
                    bufferedInputStream = null;
                    iww.x(bufferedInputStream);
                    httpURLConnection.disconnect();
                    throw th;
                }
            } catch (Exception e6) {
                e = e6;
                try {
                    httpURLConnection.disconnect();
                } catch (Throwable th4) {
                }
                try {
                    throw e;
                } catch (Throwable th5) {
                    th = th5;
                }
            }
        } catch (Exception e7) {
            e = e7;
            outputStream = null;
            httpURLConnection.disconnect();
            throw e;
        } catch (Throwable th6) {
            th = th6;
            outputStream = null;
            iww.a(outputStream);
            throw th;
        }
    }

    private void a(OutputStream outputStream, File file, iwx.a aVar) throws Exception {
        FileInputStream fileInputStream;
        long length = file.length();
        DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
        a(dataOutputStream, file.getName(), length);
        try {
            fileInputStream = new FileInputStream(file);
            try {
                byte[] bArr = new byte[8192];
                while (true) {
                    int read = fileInputStream.read(bArr);
                    if (read > 0) {
                        dataOutputStream.write(bArr, 0, read);
                        dataOutputStream.flush();
                    } else {
                        iww.x(fileInputStream);
                        b(dataOutputStream);
                        dataOutputStream.flush();
                        iww.a(dataOutputStream);
                        return;
                    }
                }
            } catch (Exception e) {
                e = e;
                try {
                    throw e;
                } catch (Throwable th) {
                    th = th;
                }
            }
        } catch (Exception e2) {
            e = e2;
            fileInputStream = null;
            throw e;
        } catch (Throwable th2) {
            th = th2;
            fileInputStream = null;
            iww.x(fileInputStream);
            throw th;
        }
    }

    private static void a(OutputStream outputStream, String str, long j) throws IOException {
        b("--", outputStream);
        b("e2cbeeea-d3e2-4f59-af36-438b4ffa155d", outputStream);
        b(CharsetUtil.CRLF, outputStream);
        b("Content-Disposition: form-data; name=\"uploadfile\"; filename=\"" + str + "\"", outputStream);
        b(CharsetUtil.CRLF, outputStream);
        b("Content-Type: application/pdf", outputStream);
        b(CharsetUtil.CRLF, outputStream);
        b("Content-Length: " + j, outputStream);
        b(CharsetUtil.CRLF, outputStream);
        b(CharsetUtil.CRLF, outputStream);
    }

    /* JADX INFO: finally extract failed */
    private long ar(File file) {
        String name = file.getName();
        long length = file.length();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            a(byteArrayOutputStream, name, length);
            b(byteArrayOutputStream);
            long length2 = ((long) byteArrayOutputStream.toByteArray().length) + length;
            iww.a(byteArrayOutputStream);
            return length2;
        } catch (IOException e) {
            iww.a(byteArrayOutputStream);
            return -1;
        } catch (Throwable th) {
            iww.a(byteArrayOutputStream);
            throw th;
        }
    }

    private static void b(OutputStream outputStream) throws IOException {
        b(CharsetUtil.CRLF, outputStream);
        b("--", outputStream);
        b("e2cbeeea-d3e2-4f59-af36-438b4ffa155d", outputStream);
        b("--", outputStream);
        b(CharsetUtil.CRLF, outputStream);
    }

    private static void b(String str, OutputStream outputStream) throws IOException {
        outputStream.write(str.getBytes(AsyncHttpResponseHandler.DEFAULT_CHARSET));
    }

    private HashMap<String, String> cET() {
        OfficeApp arx = OfficeApp.arx();
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("Connection", "Keep-Alive");
        hashMap.put("Client-Type", "wps-android");
        hashMap.put("Client-Ver", arx.cqM);
        hashMap.put("Client-Chan", arx.arB());
        hashMap.put("Client-Lang", eip.dHN);
        hashMap.put(SpeechConstant.IST_SESSION_ID, fok.bBq().getWPSSid());
        return hashMap;
    }

    private static String r(Map<String, String> map) {
        StringBuffer stringBuffer = new StringBuffer();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            stringBuffer.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
        }
        String stringBuffer2 = stringBuffer.toString();
        return stringBuffer2.endsWith("&") ? stringBuffer2.substring(0, stringBuffer2.length() - 1) : stringBuffer2;
    }

    public final int DV(String str) {
        a aVar = new a((byte) 0);
        aVar.url = this.kgJ + "?uid=" + str;
        aVar.dyQ = cET();
        try {
            JSONObject jSONObject = new JSONObject(a(aVar));
            String string = jSONObject.getString(SpeechUtility.TAG_RESOURCE_RESULT);
            JSONObject jSONObject2 = jSONObject.getJSONObject(SpeechEvent.KEY_EVENT_RECORD_DATA);
            if (string.equals("ok")) {
                return Integer.valueOf(jSONObject2.optString(NotificationCompat.CATEGORY_STATUS)).intValue();
            }
        } catch (Exception e) {
        }
        return -1;
    }

    public final String DW(String str) {
        ArrayList arrayList = new ArrayList();
        HashMap<Integer, List<igd>> ctk = ibz.cpg().jgv.ctk();
        for (Integer num : ctk.keySet()) {
            List<igd> list = ctk.get(num);
            if (list != null && list.size() > 0) {
                for (igd igd : list) {
                    Bitmap bitmap = igd.getBitmap();
                    PDFPage Co = ifz.ctd().Co(num.intValue() + 1);
                    arrayList.add(new ixb(iwv.E(bitmap), String.valueOf(num.intValue() + 1), String.valueOf(igd.crS().left / Co.getWidth()), String.valueOf(igd.crS().top / Co.getHeight()), String.valueOf((int) (((double) igd.crS().width()) + 0.5d)), String.valueOf((int) (((double) igd.crS().height()) + 0.5d))));
                }
            }
        }
        TreeMap treeMap = new TreeMap(new Comparator<String>() {
            /* class defpackage.ixa.AnonymousClass2 */

            /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
            @Override // java.util.Comparator
            public final /* synthetic */ int compare(String str, String str2) {
                return str.compareTo(str2);
            }
        });
        treeMap.put("contractId", str);
        treeMap.put("signaturePositions", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(arrayList));
        a aVar = new a((byte) 0);
        aVar.url = this.kgK;
        aVar.dyQ = cET();
        try {
            JSONObject jSONObject = new JSONObject(a(aVar.DX(r(treeMap))));
            if (jSONObject.getString(SpeechUtility.TAG_RESOURCE_RESULT).equals("ok")) {
                return jSONObject.optString("download");
            }
        } catch (Exception e) {
        }
        return null;
    }

    public final String a(File file, int i, iwx.a aVar) {
        try {
            a aVar2 = new a((byte) 0);
            aVar2.url = this.itd + "?pages=" + i;
            aVar2.dyQ = cET();
            JSONObject jSONObject = new JSONObject(a(aVar2, file, (iwx.a) null));
            if (jSONObject.getString(SpeechUtility.TAG_RESOURCE_RESULT).equals("ok")) {
                return jSONObject.optString("contractId");
            }
            return null;
        } catch (Exception e) {
            return null;
        }
    }

    public final int eq(String str, String str2) {
        TreeMap treeMap = new TreeMap(new Comparator<String>() {
            /* class defpackage.ixa.AnonymousClass1 */

            /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
            @Override // java.util.Comparator
            public final /* synthetic */ int compare(String str, String str2) {
                return str.compareTo(str2);
            }
        });
        treeMap.put("contractId", str);
        treeMap.put("fhash", lwl.IM(str2));
        a aVar = new a((byte) 0);
        aVar.url = this.kgL;
        aVar.dyQ = cET();
        try {
            JSONObject jSONObject = new JSONObject(a(aVar.DX(r(treeMap))));
            if (jSONObject.getString(SpeechUtility.TAG_RESOURCE_RESULT).equals("ok")) {
                return Integer.valueOf(jSONObject.optString(NotificationCompat.CATEGORY_STATUS)).intValue();
            }
        } catch (Exception e) {
        }
        return -1002;
    }
}